home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86v302b.arc / 10RELOC.DOC < prev    next >
Encoding:
Text File  |  1987-04-08  |  31.2 KB  |  637 lines

  1. CHAPTER 10   RELOCATION AND LINKAGE                       10-1
  2.  
  3.  
  4. A86 allows you to produce either .COM files, which can be run 
  5. immediately as standalone programs, or .OBJ files, to be fed to 
  6. the MS-DOS LINK program.  In this chapter I'll discuss .OBJ mode 
  7. of A86.  
  8.  
  9.  
  10. .OBJ Production Made Easy 
  11.  
  12. I'll start by giving you the minimum amount of information you 
  13. need to know to produce .OBJ files.  If you are writing short 
  14. interface routines, and do not want to concern yourself with the 
  15. esoterica of OBJ files (segments, groups, publics, etc.), you can 
  16. survive quite nicely by reading only this section.  
  17.  
  18. There are two ways you can cause A86 to produce a .OBJ file as 
  19. its object output.  One way is to explicitly give .OBJ as the 
  20. output file name: for example, you can assemble the source file 
  21. FOO.8 by giving the command "A86 FOO.8 FOO.OBJ".  The other way 
  22. is to specify the switch +O (letter O not digit 0).  This is 
  23. illustrated by the invocation "A86 +O FOO.8", which will have the 
  24. same effect as the first invocation.  
  25.  
  26. My design philosophy for .OBJ production is to accommodate two 
  27. types of user.  The first type of user is writing new code, to 
  28. link to other (usually high-level language) modules.  That person 
  29. should be able to write the module with a minimum of red tape, 
  30. and have A86 do the right thing.  The second type of user has 
  31. existing modules written for Intel/IBM assemblers, and wants to 
  32. port them to A86.  A86 should recognize and act upon all the 
  33. relocation directives (SEGMENT, GROUP, PUBLIC, EXTRN, NAME, END) 
  34. given.  The assembly should work even if several files, assembled 
  35. separately under the Intel/IBM assembler, are fed to a single A86 
  36. assembly.  You'll see if you read on through this entire chapter 
  37. that the multiple-files requirement causes A86 to interpret some 
  38. of the relocation directives a little differently (while 
  39. achieving compatible results).  
  40.  
  41. Let's suppose you're writing new code: for example, an interface 
  42. routine to the "C" language, that multiplies a 16-bit number by 
  43. 10.  "C" pushes the input number onto the stack, before calling 
  44. your routine.  Your code needs to get the number, multiply it by 
  45. 10, and return the answer in the AX register.  You can code it as 
  46. follows: 
  47.  
  48. _MUL10:          ; "C" expects all public names to start with "_"
  49.   PUSH BP        ; "C" expects BP to be preserved
  50.   MOV BP,SP      ; we use BP to address the stack
  51.   MOV AX,[BP+4]  ; fetch the number N, beyond BP and the ret addr
  52.   ADD AX,AX      ; 2N
  53.   MOV BX,AX      ; 2N is saved in BX
  54.   ADD AX,AX      ; 4N
  55.   ADD AX,AX      ; 8N
  56.   ADD AX,BX      ; 8N + 2N = 10N
  57.   POP BP         ; BP is restored
  58.   RET            ; go back to caller 
  59.                                                           10-2
  60. These 11 lines can be your entire source file!  If you name the 
  61. file MUL10.8, A86 will create an object file MUL10.OBJ, that 
  62. conforms to the standard SMALL model of computation for high-
  63. level languages.  If you use RETF instead of RET (thus, by the 
  64. way, getting the operand from BP+6 instead of BP+4), the object 
  65. module will conform to the standard LARGE model of computation.  
  66. All the red-tape information required by the high-level language 
  67. is provided implicitly by A86.  I'll go through this information 
  68. in detail later, but you should need to read about it only if 
  69. you're curious.  
  70.  
  71. What happens if you need to access symbols outside the module 
  72. you're assembling?  If the type of the symbol is correctly 
  73. guessed from the instruction that refers to it, then you can 
  74. simply refer to it, and leave it undefined within the module.  
  75. For example, if A86 sees the instruction CALL PRINT with PRINT 
  76. undefined, it will assume that PRINT is a NEAR procedure.  If 
  77. PRINT is never defined within the module, A86 will act as if you 
  78. declared PRINT via the directive EXTRN PRINT:NEAR.  The address 
  79. of PRINT will be plugged into your instruction by LINK when it 
  80. combines A86's .OBJ file with the high-level language's .OBJ 
  81. files, to make the final program.  
  82.  
  83. In general, the undefined operand to any CALL or JMP instruction 
  84. is assumed to be NEAR.  The second (source) operand to a MOV or 
  85. arithmetic instruction is assumed to be ABS (i.e., an immediate 
  86. constant).  An undefined first (destination) operand is assumed 
  87. to be a simple memory variable, of the same size (BYTE or WORD) 
  88. as the register given in the second operand.  If your external 
  89. symbol does not comply with these guidelines, you need to declare 
  90. it with an EXTRN before you use it.  (You can also use EXTRN to 
  91. declare types of non-complying forward-references within your 
  92. module, as you'll see later.) 
  93.  
  94. At this point, if you're a casual user, I think you've read 
  95. enough to get going!  Read further only if you wish; or if you 
  96. get stuck, and need to master the esoterica.  
  97.  
  98.  
  99. Overview of Relocation and Linkage
  100.  
  101. When you assemble a program directly into a .COM file, the 
  102. program has just two forms: the source program, that you can 
  103. understand, and the .COM file, that the computer can "understand" 
  104. (i.e., execute).  A .OBJ file is an intermediate format: neither 
  105. you nor the (executing) computer can make sense out a .OBJ file; 
  106. only programs like LINK interpret .OBJ files.  The purpose of a 
  107. .OBJ file is to allow you to assemble or compile just a part of a 
  108. program.  The other parts (also in the form of .OBJ files) can be 
  109. produced at a different time; often by a different assembler or 
  110. compiler, whose source files are in a different language.  It's 
  111. easy to see where the word "linkage" comes from: the LINK program 
  112. puts the pieces of a program together.  The "relocation" comes 
  113. because the assembler or compiler that makes a given program 
  114. piece doesn't know how many other pieces will come before it, or 
  115. how big the other pieces will be.  Each piece is constructed as 
  116. if it started at location 0 within the program; then LINK 
  117. "relocates" the piece to its true location.  
  118.                                                           10-3
  119. Many of the relocation features of 86 assembly language are 
  120. couched in terms of LINK's point of view, so we must look at the 
  121. way LINK sees things.  LINK calls a .OBJ file an "object module", 
  122. or just "module".  Each module has a NAME, that can be referred 
  123. to when LINK issues diagnostic messages, such as error messages 
  124. and symbol maps.  If a program symbol is used only within a 
  125. single module, it does not need to be given to LINK, except 
  126. possibly to pass along to a symbolic debugger.  On the other 
  127. hand, if a program symbol is defined in one module and referenced 
  128. in other modules, then LINK needs to know the name of the symbol, 
  129. so it can resolve the references.  Such a symbol is PUBLIC in the 
  130. module in which it is defined; it is "external" in the other 
  131. modules, containing references to it.  Finally, exactly one 
  132. module in a program must contain the starting location for the 
  133. program; that module is called the "main module", and it must 
  134. supply the starting address (which is not necessarily at the 
  135. beginning of the module).  
  136.  
  137. In the 86 family of microprocessors, the LINK system also does 
  138. much to manage the memory segments that a program will fit into, 
  139. and get its data from.  The (grotesquely ornate) level of support 
  140. for segmentation was dictated by Intel when it specified (and IBM 
  141. and the compiler-makers accepted) the format that .OBJ files will 
  142. have.  I attended the fateful meeting at Intel, in which the 
  143. crucial design decisions were made.  I regret to say that I sat 
  144. quietly, while engineers more senior than I applied their fertile 
  145. imaginations to construct fanciful scenarios which they felt had 
  146. to be supported by LINK.  Let's now review the resulting 
  147. segmentation model.  
  148.  
  149. The parts of a program, as viewed by LINK, come in three 
  150. different sizes: they can be (1) pieces of a single segment, (2) 
  151. an entire single segment, or (3) a sequence of consecutive 
  152. segments in 86 memory.  Size (1) should have been called 
  153. something like FRAGMENT, but is instead called SEGMENT.  Size (2) 
  154. should have been called SEGMENT, but is instead called GROUP.  
  155. Size (3) should have been called "group", but is instead called 
  156. "class".  Let me cling to the sensible terminology for one more 
  157. paragraph, while I describe the worst scenario Intel wanted to 
  158. support; then when I discuss individual directives, I'll 
  159. regretfully revert to the official terminology.  
  160.                                                           10-4
  161. The scenario is as follows: suppose you have a program that 
  162. occupies about 100K bytes of memory.  The program contains a core 
  163. of 20K bytes of utility routines that every part of the program 
  164. calls.  You'd like every part of the program to be able to call 
  165. these routines, using the NEAR form to save memory.  By gum, you 
  166. can do it!  You simply(!) slice the program into three fragments: 
  167. the utility routines will go into fragment U, and the rest of the 
  168. program will be split into equal-sized 40K-byte fragments A and 
  169. B.  Now you arrange the fragments in 8086 memory in the order 
  170. A,U,B.  The fragments A and U form a 60K-byte block, addressed by 
  171. a segment-register value G1, that points to the beginning of A.  
  172. The fragments U and B form another 60K-byte block addressed by a 
  173. segment-register value G2, that points to the beginning of U.  If 
  174. you set the CS register to G1 when A is executing, and G2 when B 
  175. is executing, the U fragment is accessible at all times.  Since 
  176. all direct JMPs and CALLs are encoded as relative offsets, the U-
  177. code will execute direct jumps correctly whether addressed by G1 
  178. with a huge offset, or G2 with a small offset.  Of course, if U 
  179. contains any absolute pointers referring to itself (such as an 
  180. indirect near JMP or CALL), you're in trouble.  
  181.  
  182. It's now been nine years since the fateful design meeting took 
  183. place, and I can report that the above scenario has never taken 
  184. place in the real world.  And I can state with some authority 
  185. that it never will.  The reason is that the only programs that 
  186. exceed 64K bytes in size are coded in high-level language, not 
  187. assembly language.  High-level language compilers follow a very, 
  188. very restricted segmentation model-- no existing model comes 
  189. remotely close to supporting the scheme suggested by the 
  190. scenario.  But the 86 assembly language can support it-- the 
  191. directives "G1 GROUP A,U" and "G2 GROUP B,U", followed by chunks 
  192. of code of the appropriate object size, headed by directives "A 
  193. SEGMENT", "B SEGMENT", and "U SEGMENT".  The LINK program is 
  194. supposed to sort things out according to the scenario; but I 
  195. can't say (and I have my doubts) if it actually succeeds in doing 
  196. so.  
  197.  
  198. The concept of "class" was added as an afterthought, to implement 
  199. the more sensible and usable features that outsiders thought 
  200. GROUPs were implementing;  namely, the ability to specify that 
  201. different (and disjoint!) segments occur consecutively in memory.  
  202. This allows programs to be arranged in a consistent manner-- for 
  203. example, with all program code followed by all static data 
  204. segments followed by all dynamically-allocated memory.  
  205.                                                           10-5
  206. The NAME Directive
  207.  
  208. Syntax:   NAME module_name
  209.  
  210. The NAME directive specifies that "module_name" be given to LINK 
  211. as the name of the module produced by this assembly.  The symbol 
  212. "module_name" can be used elsewhere in your program without 
  213. conflict: it can even, if you like, be a built-in assembler 
  214. mnemonic (e.g. "NAME MOV" is acceptable)!  
  215.  
  216. If you do not provide a NAME directive, A86 will use the name of 
  217. the output object file, without the .OBJ extension.   If you 
  218. provide more than one NAME directive, A86 will use the last one 
  219. given, with no error reported.  
  220.  
  221.  
  222.  
  223. The PUBLIC Directive
  224.  
  225. Syntax:   PUBLIC  sym1, sym2, sym3, ...
  226.           PUBLIC
  227.  
  228. The PUBLIC directive allows you to explicitly list the symbols 
  229. defined in this assembly, that can be used by other modules.  If 
  230. you do not give any PUBLIC directives in your program, A86 will 
  231. use every relocatable label and variable name in your program, 
  232. except local labels (the redefinable labels consisting of a 
  233. letter followed by digits: L7, M1, Q234, etc.).  Symbols EQUated 
  234. to constants, and symbols defined within structures and DATA 
  235. SEGMENTs, are not implicitly declared PUBLIC: you have to 
  236. explicitly include them in a PUBLIC directive.  
  237.  
  238. A86 maintains an internal flag, telling it whether to figure out 
  239. for itself which symbols are PUBLIC, or to let the program 
  240. explicitly declare them.  The flag starts out "implicit", and is 
  241. set to "explicit" only if A86 sees a PUBLIC directive with no 
  242. names at all, or a PUBLIC directive containing at least one name 
  243. that would have been implicitly made PUBLIC.  
  244.  
  245. If you are writing new code, you'll probably want to keep the 
  246. flag "implicit".  You use the PUBLIC directive only for those 
  247. symbols which have the form of local labels, but aren't (e.g., a 
  248. memory variable I1987 for 1987 income); and for absolute values 
  249. that are globally accessed -- e.g. specify "PUBLIC 
  250. OPEN_FILES_LIMIT" for a symbol defined as "OPEN_FILES_LIMIT EQU 
  251. 20".  
  252.  
  253. If you are porting existing code, that code will already have 
  254. PUBLIC directives in it, and A86 will go to "explicit" mode, 
  255. duplicating the functionality of other assemblers.  
  256.  
  257. The PUBLIC directive with no names is used to force "explicit" 
  258. mode, thus causing (if there are no further PUBLICs with names) 
  259. the .OBJ file to declare no symbols PUBLIC.  
  260.                                                           10-6
  261. There is another side effect to the PUBLIC directive: if a symbol 
  262. is declared PUBLIC in a module, it had better be defined in that 
  263. module.  If it isn't then A86 includes it in the .ERR listing of 
  264. undefined symbols in the module, and suppresses output of the 
  265. object file.
  266.  
  267.  
  268. The EXTRN Directive 
  269.  
  270. Syntax:  EXTRN  sym1:type, sym2:type, ...
  271.  
  272.      where "type" is one of:  BYTE WORD DWORD QWORD TBYTE FAR 
  273.             or synonymously:  B    W    D     Q     T     F
  274.                          or:  NEAR  ABS
  275.  
  276. The EXTRN directive allows you to attach a type to a symbol that 
  277. may not yet be defined (and may never be defined) within your 
  278. program.  This is often necessary for the assembler to generate 
  279. the correct instruction form when the symbol is used as an 
  280. operand.  All the possible types except ABS are defined elsewhere 
  281. in the A86 language, but I list them again here for convenience: 
  282.  
  283.    B or BYTE:  byte-sized memory variable
  284.    W or WORD:  word (2 byte) sized memory variable
  285.    D or DWORD: doubleword (4-byte) sized memory variable
  286.    Q or QWORD: quadword (8-byte) sized memory variable
  287.    T or TWORD: 10-byte-sized memory variable
  288.    NEAR:       program label accessed within a segment
  289.    FAR:        program label accessed from outside this segment
  290.    ABS:        an absolute number (i.e., an immediate constant)
  291.  
  292. An example of EXTRN usage is as follows: suppose there is a word 
  293. memory variable IFARK in your program.  The variable might be 
  294. declared at the end of the program; or it might be defined in a 
  295. module completely outside of this program.  Without an EXTRN 
  296. directive, A86 will assemble an instruction such as "MOV 
  297. AX,IFARK" as the loading of an immediate constant IFARK into the 
  298. AX register.  If you place the directive "EXTRN IFARK:W" at the 
  299. top of your program, you'll get the correct instruction form for 
  300. MOV AX,IFARK-- moving a word memory variable into the AX 
  301. register.  
  302.  
  303. A86 will allow more than one EXTRN directive for a given symbol, 
  304. as long as the same type is given every time.  A86 will even 
  305. allow an EXTRN directive for a symbol that has already been 
  306. defined, as long as the type declared is consistent with the 
  307. symbol's definition.  These allowances exist so that you can 
  308. assemble multiple files written for another assembler, that had 
  309. been fed separately to that assembler.  
  310.                                                           10-7
  311. Note that EXTRN is viewed by A86 quite differently by A86 than by 
  312. other assemblers.  In fact, if it weren't for those other 
  313. assemblers, I'd use the mnemonic DECLARE instead of EXTRN.  A86 
  314. doesn't really use EXTRN to determine which symbols are external-
  315. - it uses those symbols that are undefined at the end of 
  316. assembly.  As I stated earlier in the chapter, an undefined 
  317. symbol can be referenced without being declared via EXTRN.  
  318. Conversely, a defined symbol can be declared (and redeclared) via 
  319. EXTRN; being defined, such a symbol will not be specified 
  320. "external" in the .OBJ file.  
  321.  
  322. Because EXTRN is useful in forward-reference situations, it is 
  323. now recognized even when A86 is assembling a .COM file.  
  324.  
  325. For those of you who are accustomed to the more traditional use 
  326. of EXTRN, and who do not like external records to be created 
  327. "behind your back", A86 offers the "+x" option.  If you include 
  328. "+x" in the program invocation, A86 will require that all 
  329. undefined symbols be explicitly declared via an EXTRN.  Any 
  330. undefined, undeclared symbols will be included in the .ERR 
  331. listing of undefined symbols, and object file output will be 
  332. suppressed.
  333.  
  334.  
  335. MAIN: The Starting Location for a Program
  336.  
  337. I've already stated that exactly one module in a program is the 
  338. "main" module, containing the starting address of the entire 
  339. program.  In A86 when assembling .OBJ files, the starting address 
  340. is given by the label MAIN.  You simply provide the label "MAIN:" 
  341. where you want the program to start.  The module containing MAIN 
  342. is the main module.  
  343.  
  344.  
  345. The END Directive
  346.  
  347. Syntax:  END
  348.          END start_addr
  349.  
  350. The END directive is used by other assemblers for two purposes, 
  351. both of which are now a little silly.  The first purpose is to 
  352. signal the end of assembly.  This was necessary back in the days 
  353. when source files were input on media such as paper tape: you had 
  354. to tell the assembler explicitly that the contents of the tape 
  355. has ended.  Today the operating system can tell you when you've 
  356. reached the end of the file, so this function is an anachronism.  
  357.  
  358. The second purpose of END is, nonsensically, to allow you to 
  359. specify the starting location of the program.  I suppose the 
  360. person who wrote the first assembler back in the 1950's was too 
  361. short on memory to implement a separate START directive, or a 
  362. MAIN label like A86 has, and decided to let END do double-duty.  
  363. I've always considered the example "END START" to have an Alice-
  364. in-Wonderland quality; it is fuel for the high-level-language 
  365. snobs who like to attack assembly language.  Please defeat the 
  366. snobs, and use "MAIN:" if you are writing new code.  
  367.                                                           10-8
  368. For compatibility, A86 treats "END start_addr" exactly the same as 
  369. if you had coded "MAIN EQU start_addr".  Note that if you want 
  370. your program to assemble under both A86 and that other assembler, 
  371. you can specify "END MAIN"-- A86 treats MAIN EQU MAIN as a legal 
  372. redefinition of the symbol MAIN.  
  373.  
  374. A86 ignores END when there is no starting-address operand, thus 
  375. allowing assembly of multiple files written for other assemblers.  
  376.  
  377.  
  378. The SEGMENT Directive
  379.  
  380. Syntax:  seg_name SEGMENT [align] [combine] ['class_name']
  381.  
  382. where "align" is one of:  BYTE   WORD   PARA   PAGE
  383.     "combine" is one of:  PUBLIC  STACK  COMMON  MEMORY  AT number
  384.  
  385. The SEGMENT directive says that assembled object code will 
  386. henceforth go to a block of code whose name is "seg_name".  
  387. "seg_name" is a symbol that represents a value that can be loaded 
  388. into a segment register.  If "seg_name" is not declared in a 
  389. GROUP directive, then its value should in fact be loaded into a 
  390. segment register, in order to address the code.  If "seg_name" is 
  391. declared in a GROUP directive, then the code is a a part of the 
  392. segment addressed by the name of the group.  
  393.  
  394. A program can consist of any number of named segments, to be 
  395. combined in numerous exotic ways to produce the final program.  
  396. You can redirect your object output from one segment to another 
  397. in your assembly, by providing a SEGMENT directive before each 
  398. piece of code.  You can even return to a segment you started 
  399. earlier, by repeating a SEGMENT with the same name-- the 
  400. assembler just picks up where it left off, subject to some 
  401. possible skipping for memory-alignment, that I'll describe 
  402. shortly.  
  403.  
  404. The specifications following the word SEGMENT help to describe 
  405. how the code in this module's part of the segment will be 
  406. combined with code for the same segment name given in other 
  407. modules; and also how this named segment will be grouped with 
  408. other named segments.  Other assemblers require the 
  409. specifications to be given in the order indicated.  A86 will 
  410. accept any order, and will accept commas between the 
  411. specifications if you want to provide them.  The only restriction 
  412. is that "AT number" must be followed by a comma if it is not the 
  413. last specification on the line.  
  414.  
  415. The "align" specification tells if each piece of code within the 
  416. segment should be aligned so that its starting address is an even 
  417. multiple of some number.  BYTE alignment means there is no 
  418. requirement; WORD alignment requires each piece to start at a 
  419.                                                           10-9
  420. multiple of 2; PARA alignment, at a multiple of 16; PAGE 
  421. alignment, at a multiple of 256.  For example, suppose you have a 
  422. segment containing memory variables.  You can declare the segment 
  423. with the statement "VAR_DATA SEGMENT WORD", which insures that 
  424. the segment is aligned to an even memory address.  That way you 
  425. can insure that all 16-bit and bigger memory quantities in the 
  426. segment are aligned to even addresses, for faster access on the 
  427. 16-bit machines of the 86 family.  
  428.  
  429. There are special rules governing alignment for multiple pieces 
  430. of the same named segment within the same program module.  Other 
  431. assemblers outlaw conflicting alignment specifications in this 
  432. situation; A86 accepts them, and uses the strictest specification 
  433. given.  Furthermore, the alignment given for any specification 
  434. beyond the first will control the alignment for that piece of 
  435. code within this module's chunk.  For example, if a program 
  436. contains two pieces of code headed by "VAR_DATA SEGMENT WORD", 
  437. A86 will insert a byte between the pieces if the first piece has 
  438. an odd number of bytes.  This insures correct assembly for 
  439. multiple files written for another assembler.  
  440.  
  441. If no "align" type is given for any of the pieces of a named 
  442. segment, an alignment of PARA is assumed.  
  443.  
  444.  
  445. The "combine" specification tells how the chunk of code from this 
  446. module will be combined with the chunks of the same named 
  447. segment, that come from other modules.  Yes, I know, that sounds 
  448. like what "align" does; but "combine" takes a different, more 
  449. major point of view: 
  450.  
  451. * PUBLIC is the kind of combination we've been talking about all 
  452.   along: each piece of the segment is located off the end of the 
  453.   previously linked piece, subject to possible gaps for 
  454.   alignment.  The size of the segment is the sum of the sizes of 
  455.   the pieces, plus the sizes of the gaps.  
  456.  
  457. * STACK is a combination-type reserved for the system's stack 
  458.   segment.  To illustrate how STACK segment chunks are combined, 
  459.   let's describe the only way a stack segment should ever be 
  460.   used.  We'll call the segment PROG_STACK; and we declare it as 
  461.   follows: 
  462.  
  463.     PROG_STACK SEGMENT WORD STACK
  464.        DW 100 DUP (?)
  465.     TOP_OF_STACK:
  466.  
  467.   The code just given declares a stack area of 200 bytes (100 
  468.   words) for this module.  If identical code occurs in each of 
  469.   three modules which are then linked together, the resulting 
  470.   PROG_STACK segment will have 600 bytes (the sizes are added), 
  471.   but TOP_OF_STACK will be the same address (600) for each module 
  472.   (each piece is overlayed at the top of the segment).  That way, 
  473.   every module can declare and access the top of the stack, which 
  474.   is the only static part of the stack that any code should ever 
  475.   refer to.  
  476.                                                           10-10
  477.  
  478. * COMMON is a type of memory area supported by FORTRAN.  Each 
  479.   module's chunk of a COMMON segment starts at location 0, and 
  480.   overlaps (usually duplicates) the pieces from all the other 
  481.   modules.  The size of a COMMON segment is the size of the 
  482.   largest chunk.  
  483.  
  484. * MEMORY is supposed to be another kind of COMMON segment, that 
  485.   is distinguished by automatically being located beyond all 
  486.   other segments in memory.  The MS_DOS LINK program, however, 
  487.   does not implement MEMORY segments, and instead treats them 
  488.   identically to PUBLIC (not COMMON!) segments.  I can see no 
  489.   useful purpose to the MEMORY combine-type, since the 
  490.   functionality can be achieved by putting a COMMON segment into 
  491.   a 'class' by itself, that goes above all the other classes.  So 
  492.   don't use MEMORY.  
  493.  
  494.   Sorry, I don't support the assembly of multiple files written 
  495.   for other assemblers, that contain STACK, COMMON, or MEMORY 
  496.   segments.  If I did, I would have to detect the file breaks, 
  497.   and duplicate the overlapping functionality of these segment 
  498.   types.  Since I don't think anybody out there is using these 
  499.   esoteric types, I didn't bother to support them to that extent.  
  500.   Objections, anyone?  
  501.  
  502. * "AT number" defines a non-combinable segment at the absolute 
  503.   memory location whose segment register value is "number".  This 
  504.   form is useful for initializing data in fixed locations, such 
  505.   as the 86 interrupt vector (IVECTOR SEGMENT AT 0 followed by 
  506.   ORG 4 * INT_NUMBER), or for reading fixed memory locations, 
  507.   such as the BIOS variables area (BIOS_DATA SEGMENT AT 040).  
  508.  
  509. The combine-type specification can be repeated in subsequent 
  510. pieces of a given segment, but if it is, it must be the same in 
  511. all pieces.  
  512.  
  513. Finally, if no combine-type is ever given for a named segment in 
  514. a module, that segment is non-combinable-- no other modules may 
  515. define that segment; the code given in the one module constitutes 
  516. the entire segment.  
  517.  
  518. The last specification available on a SEGMENT line is the class 
  519. name, which is identified by being enclosed in single quotes.  
  520. Unlike a segment name, which can be used as an instruction 
  521. operand an hence cannot conflict with other assembler symbols, a 
  522. class name can be assigned without regard to its usage elsewhere 
  523. in the program.  It can even be a built-in A86 mnemonic.  In 
  524. fact, both the SMALL and LARGE high-level-language models specify 
  525. the class name 'CODE' for code segments, and the SMALL model 
  526. specifies the class name 'DATA'.  
  527.  
  528. If no class name is given for a segment, A86 specifies the null 
  529. (zero-length) string as the class name.  
  530.                                                           10-11
  531. DATA SEGMENT, STRUC and CODE SEGMENT Directives
  532.  
  533. The DATA SEGMENT and STRUC directives work in .OBJ mode exactly 
  534. as they do in .COM mode-- they define a special assembly mode, in 
  535. which declarations are made, but no object code is output.  
  536. Offsets within DATA segments and structures are absolute, as in 
  537. .COM mode.  Assembly resumes as before when an ENDS or CODE 
  538. SEGMENT directive is encountered.  
  539.  
  540.  
  541. The ENDS Directive
  542.  
  543. Syntax:  [seg_name] ENDS
  544.  
  545. The ENDS directive closes out the segment currently being 
  546. assembled, and returns assembly to the segment being assembled 
  547. before the last SEGMENT directive.  The "seg_name", if given, 
  548. must match the name in that last SEGMENT directive.  ENDS allows 
  549. you to "nest" segments inside one another.  For example, you can 
  550. declare some static data variables that are specific to a certain 
  551. section of code at the top of that section: 
  552.  
  553.   _DATA SEGMENT BYTE PUBLIC 'DATA'
  554.     VAR1  DB ?
  555.     VAR2  DB ?
  556.   _DATA ENDS
  557.  
  558. These four lines can be inserted inside any other segment being 
  559. assembled.  They will cause the two variable allocations to be 
  560. tacked onto the segment _DATA; and assembly will then continue in 
  561. whatever segment surrounded the four lines.  Observe that the 
  562. "nesting" does not occur in the final program; only the 
  563. presentation of the source code is nested.  
  564.  
  565. If you are not nesting segments inside one another, then the ENDS 
  566. directive serves only to lend a clean, "block-structured" 
  567. appearance to your source code.  It does not assist A86 in any 
  568. particular way; in fact, it consumes a bit more object output 
  569. memory (slightly reducing object output capacity) if you have 
  570. ENDSs, rather than just starting up new segments with SEGMENT 
  571. directives.  
  572.  
  573.  
  574. Default Outer SEGMENT
  575.  
  576. Other assemblers outlaw any code outside of a SEGMENT 
  577. declaration, forcing you to give a SEGMENT declaration before you 
  578. can assemble anything.  A86 lets you assemble just your code; you 
  579. don't have to worry about SEGMENTs if you don't want to.  
  580.  
  581. If you do provide code outside of all SEGMENT declarations, A86 
  582. performs the following steps, to find a reasonable place to put 
  583. the code: 
  584.  
  585. 1. If there are any segments explicitly declared whose name is or 
  586.    ends with "_TEXT", then the first such segment declared is 
  587.    used.  It is as if the SEGMENT declaration appeared at the top 
  588.    of, rather than within, the program.  
  589.                                                           10-12
  590. 2. If there is no such explicit segment, A86 creates a BYTE 
  591.    PUBLIC segment of class 'CODE', and proceeds to construct a 
  592.    name for the segment.  If there are no RETF instructions in 
  593.    the outer segment, the name chosen is "_TEXT", conforming to 
  594.    the SMALL model of computation.  If there is a RETF 
  595.    instruction, the name chosen is "modulename_TEXT", where 
  596.    "modulename" is the name of this module.  Recall that 
  597.    "modulename" comes from the NAME directive if there is one; 
  598.    from the name of the .OBJ file if there isn't.  
  599.  
  600.  
  601. The GROUP Directive
  602.  
  603. Syntax:  group_name GROUP seg_name1, seg_name2, ...
  604.  
  605. The GROUP directive causes A86 to tell LINK that all the listed 
  606. segments can fit into a single 64K-byte block of memory, and 
  607. instruct LINK to make that fit.  (If they won't fit, LINK will 
  608. issue an error message.)  Having declared the group, you can then 
  609. use "group_name" as the segment register value that will allow 
  610. simultaneous access to all the named segments.  The order of 
  611. names given in the list does not necessarily determine the order 
  612. the segments will finally appear within the group.  
  613.  
  614. The most useful application of the GROUP directive is to allow 
  615. you to structure the pieces of a program, all of whose code and 
  616. data will fit into a single 64K segment.  You organize the pieces 
  617. into SEGMENTs, and declare all the SEGMENTs to be within the same 
  618. GROUP.  When the program starts, all segment registers are set to 
  619. point to the GROUP, and you never have to worry about segment 
  620. registers again in the program.  
  621.  
  622. WARNING: If your segments will be GROUPed in the final program, 
  623. you should have the appropriate GROUP directive in every module 
  624. assembled.  If you don't, then any memory pointers generated will 
  625. be relative to the beginning of the individual named segments, 
  626. not to the beginning of the whole group.  
  627.  
  628. Because of the obscure scenario I described in the Overview 
  629. section, Intel does not prohibit more than one GROUP from 
  630. containing some of the same segments; so neither does A86.  Any 
  631. pointers within a segment will be calculated from the beginning 
  632. of the last GROUP that the segment was declared within.  But 
  633. again, I have my doubts as to whether LINK will handle this 
  634. correctly.  
  635.  
  636.  
  637.